package demo7;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Person {
    private String name;

    public Person(){
        System.out.println("1:Person对象的构造器被调用了");
    }
    public String getName() {
        return name;
    }

    @Value("张三")
    public void setName(String name) {
        this.name = name;
        System.out.println("2:name属性的 set 方法被调用");
    }

    @PostConstruct
    public void init(){
        System.out.println("3:Spring容器初始化 person对象了，调用了@PostConstruct标注的方法");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("4:Spring容器销毁 person对象了，调用了@PreDestroy标注的方法");
    }
}
